package psi.controllers;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.ext.interceptor.POST;

import psi.common.FIdConst;
import psi.services.BizlogService;
import psi.services.MainMenuService;

public class MainMenuController extends Controller {

	@Before(POST.class)
	public void mainMenuItems() {
		renderJson(new MainMenuService().mainMenuItems());
	}

	@Before(POST.class)
	public void recentFid() {
		renderJson(new MainMenuService().recentFid());
	}

	public void navigateTo() {
		String fid = getPara("fid");
		MainMenuService ms = new MainMenuService();
		ms.insertRecentFid(fid);
		
		String fidName = ms.getFIdName(fid);
		if (fidName != null) {
			new BizlogService().insertBizlog("进入模块: " + fidName, "系统");
		}

		switch (fid) {
		case FIdConst.RELOGIN:
			// 重新登录
			setSessionAttr("loginUserId", null);
			redirect("/");
			break;
		case FIdConst.BIZ_LOG:
			// 业务日志
			redirect("/Home/Bizlog");
			break;
		default:
			redirect("/");
		}
	}
}
